#!/usr/local/BLBIN/bin/php
<?php
/**
*
* @ This file is created by http://DeZender.Net
* @ deZender (PHP7 Decoder for SourceGuardian Encoder)
*
* @ Version			:	5.0.0.0
* @ Author			:	DeZender
* @ Release on		:	14.12.2021
* @ Official site	:	http://DeZender.Net
*
*/

function get_request($url)
{
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	$response = curl_exec($ch);
	curl_close($ch);
	return trim($response);
}

function real_execute($cmd)
{
	$a = popen($cmd, 'r');

	while ($b = fgets($a, 2048)) {
		echo $b;
		ob_flush();
		flush();
	}

	pclose($a);
}

function update_license($file)
{
	global $status;
	global $ctl;
	global $plast_bin;

	if ($ctl == 'cpanel') {
		system($plast_bin . ' -q -f \'' . $file . '\' /usr/local/cpanel/3rdparty/bin/php /usr/local/cpanel/whostmgr/docroot/cgi/softaculous/cron.php &> /dev/null');
	}
	else if ($ctl == 'directadmin') {
		system($plast_bin . ' -q -f \'' . $file . '\' /usr/local/bin/php -d open_basedir=\'\' -d safe_mode=0 -d disable_functions=\'\' /usr/local/directadmin/plugins/softaculous/cron.php   &> /dev/null ');
	}
	else if ($ctl == 'vesta') {
		system($plast_bin . ' -q -f \'' . $file . '\' /usr/local/vesta/php/bin/php /usr/local/vesta/softaculous/cron.php   &> /dev/null');
	}
	else if ($ctl == 'cwp') {
		system($plast_bin . ' -q -f \'' . $file . '\' /usr/local/cwp/php/bin/php /usr/local/softaculous/cron.php     &> /dev/null');
	}
	else if ($ctl == 'hsphere') {
		system($plast_bin . ' -q -f \'' . $file . '\' /hsphere/shared/php5/bin/php-cli -d open_basedir=\'\' -d safe_mode=0 -d disable_functions=\'\' /usr/local/softaculous/cron.php  &> /dev/null');
	}
	else if ($ctl == 'emps') {
		system($plast_bin . ' -q -f \'' . $file . '\' /usr/local/emps/bin/php /usr/local/softaculous/cron.php    &> /dev/null');
	}
	else if ($ctl == 'interworx') {
		system($plast_bin . ' -q -f \'' . $file . '\' /home/interworx/bin/php /usr/local/softaculous/cron.php   &> /dev/null');
	}
	else if (($ctl == 'plesk') || ($ctl == 'ISPManager') || ($ctl == 'ispconfig')) {
		system($plast_bin . ' -q -f \'' . $file . '\' php -d open_basedir=\'\' -d safe_mode=0 -d disable_functions=\'\' /usr/local/softaculous/cron.php   &> /dev/null');
	}

	system('rm -rf \'' . $file . '\' &> /dev/null');
}

function exec_output($cmd)
{
	exec($cmd, $output, $return_var);

	if (1 < count($output)) {
		return join("\r\n", $output);
	}

	return $output[0];
}

function get_http_response_code($domain1)
{
	$ch = curl_init($domain1);
	curl_setopt($ch, CURLOPT_HEADER, true);
	curl_setopt($ch, CURLOPT_NOBODY, true);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_TIMEOUT, 30);
	$output = curl_exec($ch);
	$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
	curl_close($ch);
	return $httpcode;
}

function csf_ports()
{
	$file22 = file_get_contents('/etc/csf/csf.conf');
	$pos = strpos($file22, 'TCP_OUT = "1:65535"');

	if ($pos === false) {
		exec('sed -i \'/TCP_OUT =/c\\TCP_OUT = "1:65535"\' /etc/csf/csf.conf');
		exec('csf -r > /dev/null 2>&1');
	}

	$file22 = file_get_contents('/etc/csf/csf.conf');
	$pos = strpos($file22, 'TCP_IN = "1:65535"');

	if ($pos === false) {
		exec('sed -i \'/TCP_IN =/c\\TCP_IN = "1:65535"\' /etc/csf/csf.conf');
		exec('csf -r > /dev/null 2>&1');
	}

	$file22 = file_get_contents('/etc/csf/csf.conf');
	$pos = strpos($file22, 'UDP_IN = "1:65535"');

	if ($pos === false) {
		exec('sed -i \'/UDP_IN =/c\\UDP_IN = "1:65535"\' /etc/csf/csf.conf');
		exec('csf -r > /dev/null 2>&1');
	}

	$file22 = file_get_contents('/etc/csf/csf.conf');
	$pos = strpos($file22, 'TESTING = "0"');

	if ($pos === false) {
		exec('sed -i \'/TESTING =/c\\TESTING = "0"\' /etc/csf/csf.conf');
		exec('csf -r > /dev/null 2>&1');
	}

	$file22 = file_get_contents('/etc/csf/csf.conf');
	$pos = strpos($file22, 'UDP_OUT = "1:65535"');

	if ($pos === false) {
		exec('sed -i \'/UDP_OUT =/c\\UDP_OUT = "1:65535"\' /etc/csf/csf.conf');
		exec('csf -r > /dev/null 2>&1');
	}
}

function firewall_accept($force = flase)
{
	global $firewall_stop;
	global $firewall_stop_1;

	if (preg_match('/127.0.0.1.*api.sitepad.com/', file_get_contents('/etc/hosts'))) {
		system('sed -i -e \'s/127.0.0.1.*api.sitepad.com//g\' \'/etc/hosts\'  ');
		system('sed -i  \'/^$/d\' \'/etc/hosts\' ');
	}

	if (file_exists('/usr/sbin/csf')) {
		if (file_exists('/etc/csf/csf.conf')) {
			csf_ports();
		}
	}
}

function firewall_drop()
{
	global $firewall_stop;
	global $firewall_stop_1;

	if (!preg_match('/127.0.0.1.*api.sitepad.com/', file_get_contents('/etc/hosts'))) {
		system('echo "127.0.0.1 api.sitepad.com" >>  "/etc/hosts"');
	}

	if (file_exists('/usr/sbin/csf')) {
		if ($GLOBALS['firewall_stop_1']) {
			system('/usr/sbin/csf -e &> /dev/null');
			system('rm -rf /etc/csf/csf.error &> /dev/null');
		}

		if ($GLOBALS['firewall_stop']) {
			system('service csf start &> /dev/null');
			system('rm -rf /etc/csf/csf.error &> /dev/null');
		}
	}
}

$RED = '\\033[31m';
$Green = '\\033[32m';
$Cyan = '\\033[36m';
$NC = '\\033[0m';
$key = 'softaculous';
$api = 'https://api.begpl.com/api/getinfo?key=' . $key;
$api_license = 'https://api.begpl.com/api/license?key=' . $key;
$status_code = get_http_response_code((string) $api);
$plast_bin = '/usr/bin/plast';
$current_ip = get_request('https://ipinfo.io/ip');
$domain_show = 'https://begpl.com';
$brand_show = 'begpl.com';
$hostname_show = exec_output('hostname');
$server_type = 'VPS';
$status = false;
$server_range = 0;
$key_cmd = 'gb';
$firewall_stop = false;
$running = false;
$firewall_stop_1 = false;
$ctl = '';
$action = (1 < count($argv) ? $argv[1] : '');
echo "\n";

if (is_dir('/usr/local/directadmin')) {
	$ctl = 'directadmin';
}
else if (is_dir('/usr/local/cpanel')) {
	$ctl = 'cpanel';
}
else if (is_dir('/usr/local/cwp')) {
	$ctl = 'cwp';
}
else if (is_dir('/usr/local/vesta')) {
	$ctl = 'vesta';
}
else if (is_dir('/usr/local/vesta')) {
	$ctl = 'interworx';
}
else if (is_dir('/usr/local/ispconfig')) {
	$ctl = 'ispconfig';
}
else if (is_dir('/usr/local/mgr5/sbin/mgrctl')) {
	$ctl = 'ISPManager';
}
else if (is_dir('/usr/local/hsphere')) {
	$ctl = 'hsphere';
}
else if (is_dir('/usr/local/emps')) {
	$ctl = 'emps';
}
else if (is_dir('/usr/local/psa')) {
	$ctl = 'plesk';
}
else {
	echo "\x1b" . '[31mControl Panel is not supported ' . "\x1b" . '[0m ' . "\n";
	echo "\n";
	exit();
}

printf("\x1b" . '[32m' . $ctl . ' is  detected  ' . "\x1b" . '[0m ' . "\n");
echo "\n";
if (!file_exists('/usr/local/sitepad/cron.php') && ($ctl == 'cpanel')) {
	echo "\n";
	echo "\n";
	echo "\x1b" . '[31mSitepad is not detected ' . "\x1b" . '[0m ' . "\n";
	echo "\x1b" . '[31mYou need to install Sitepad ' . "\x1b" . '[0m ' . "\n";
	echo "\n";
	echo "\n";
	exit();
}
else if (!file_exists('/usr/local/sitepad/cron.php') && ($ctl == 'directadmin')) {
	echo "\n";
	echo "\n";
	echo "\x1b" . '[31mSitepad is not detected ' . "\x1b" . '[0m ' . "\n";
	echo "\x1b" . '[31mYou need to install Sitepad ' . "\x1b" . '[0m ' . "\n";
	echo "\n";
	echo "\n";
	exit();
}
else if (!file_exists('/usr/local/sitepad/cron.php') && ($ctl == 'vesta')) {
	echo "\n";
	echo "\n";
	echo "\x1b" . '[31mSitepad is not detected ' . "\x1b" . '[0m ' . "\n";
	echo "\x1b" . '[31mYou need to install Sitepad ' . "\x1b" . '[0m ' . "\n";
	echo "\n";
	echo "\n";
	exit();
}
else if (!file_exists('/usr/local/sitepad/cron.php') && (($ctl == 'emps') || ($ctl == 'interworx') || ($ctl == 'hsphere') || ($ctl == 'plesk') || ($ctl == 'ispconfig') || ($ctl == 'ISPManager'))) {
	echo "\n";
	echo "\n";
	echo "\x1b" . '[31mSitepad is not detected ' . "\x1b" . '[0m ' . "\n";
	echo "\x1b" . '[31mYou need to install Sitepad ' . "\x1b" . '[0m ' . "\n";
	echo "\n";
	echo "\n";
	exit();
}

if (!file_exists('/etc/redhat-release')) {
	system('yum install deltarpm  -y  1> /dev/null');
}

if (!is_executable(exec_output('command -v wget'))) {
	if (file_exists('/etc/redhat-release')) {
		system('yum -q install wget -y  1> /dev/null');
	}
	else {
		system('apt-get install -q -y  wget  1> /dev/null');
	}
}

if (!file_exists($plast_bin)) {
	printf("\x1b" . '[31m Reinstall system license again  ' . "\x1b" . '[0m ' . "\n");
	echo "\n";
	exit();
}

$output = get_request($api);

if ($status_code != '200') {
	printf("\x1b" . '[31m Something Went Wrong [Unknown Ip]   ' . "\x1b" . '[0m ' . "\n");
	echo "\n";
	exit();
}

if (!file_exists((string) $plast_bin)) {
	echo "\x1b" . '[31mReinstall system license again' . "\x1b" . '[0m' . "\n";
	echo "\n";
	exit();
}

$output = json_decode($output, true);
$expire_date = $output['expire_date'];
$get_domain_show = $output['domain_name'];
$get_brand_show = $output['brand_name'];
$get_key_cmd_show = $output['key_cmd'];

if ($get_key_cmd_show != '') {
	$key_cmd = $get_key_cmd_show;
}

if ($get_domain_show != '') {
	$domain_show = $get_domain_show;
}

if ($get_brand_show != '') {
	$brand_show = $get_brand_show;
}

echo "\n";
echo "\n";

if ($action == '--force') {
	system('rm -rf  /etc/cron.d/cplicensecron  &> /dev/null');
	system('rm -rf /usr/bin/pid/running.pid &> /dev/null');
	$current_process = getmypid();
	system('    current_process=' . $current_process . "\r\n" . '    killprocess=$( ps aux | grep LicenseCP | grep -v grep | awk \'{print  $2 }\')' . "\r\n" . '    for proc in $killprocess;do' . "\r\n" . '    if [ "$proc" != "$current_process" ];then' . "\r\n" . '    kill -9  $proc  &> /dev/null' . "\r\n" . '    fi' . "\r\n" . '    done' . "\r\n");
}

printf("\x1b" . '[36m---------------------- BeGPL Licensing System Started ----------------------  ' . "\x1b" . '[0m ' . "\n");
printf("\x1b" . '[36m| Thank you for using our Sitepad Licensing System  ' . "\x1b" . '[0m ' . "\n");
printf("\x1b" . '[36m| Our Website: ' . $domain_show . '  ' . "\x1b" . '[0m ' . "\n");
printf("\x1b" . '[36m| Server IPV4: ' . $current_ip . '  ' . "\x1b" . '[0m ' . "\n");
printf("\x1b" . '[36m| Hostname: ' . $hostname_show . '  ' . "\x1b" . '[0m ' . "\n");
printf("\x1b" . '[36m| Expiry Date: ' . $expire_date . '  ' . "\x1b" . '[0m ' . "\n");
printf("\x1b" . '[36m----------------------------------------------------------------------  ' . "\x1b" . '[0m ' . "\n");
echo "\n";
echo "\n";
echo "\n";
printf("\x1b" . '[36mIf you have any question contact us on our website.  ' . "\x1b" . '[0m ' . "\n");
printf("\x1b" . '[36mCopyright © 2019-2021 ' . $brand_show . ' . All rights reserved ' . "\x1b" . '[0m ' . "\n");
echo "\n";
echo "\n";
printf("\x1b" . '[32mPlease Wait... ' . "\x1b" . '[0m ' . "\n");
echo "\n";
echo "\n";
echo "\n";
echo "\n";
firewall_accept(true);
$output_license = get_request($api_license);
$output_license = json_decode($output_license);
$proxy_conf = $output_license->proxy_conf;
$time = time();
$file_conf = $time . '.conf';
$path_conf = '/usr/bin/.log';
$full_path = $path_conf . '/' . $file_conf;
system('mkdir -p \'' . $path_conf . '\' &> /dev/null');
file_put_contents($full_path, $proxy_conf);
update_license($full_path);
real_execute('/usr/bin/gblicensesp --hide-info');
printf("\x1b" . '[32mSitepad Updated OK ' . "\x1b" . '[0m ' . "\n");
firewall_drop();

?>